"""
添加线索页面
"""

from selenium.webdriver.common.by import By
from page.base_page import BasePage
from selenium.webdriver.support.select import Select


class AddCluePage(BasePage):
    url = '/crm/index.php?m=leads&a=add'
    # 负责人定位器
    person_locator = (By.ID, 'owner_name')
    # 公司名定位器
    company_locator = (By.ID, 'name')
    # 点击公司名定位器
    click_company = (By.CSS_SELECTOR, '#form1 > table > tbody > tr:nth-child(2) > td:nth-child(3)')
    # 公司验重定位器
    company_yanchong_locator = (By.CSS_SELECTOR,
                                'body > div:nth-child(15) > div.ui-dialog-buttonpane.ui-widget-content.ui-helper-clearfix > div > button')
    # 来源选择定位器
    source_locator = (By.ID, 'source')
    # 联系人姓名定位器
    contacts_name_locator = (By.ID, 'contacts_name')
    # 职位定位器
    position_locator = (By.ID, 'position')
    # 尊称选择定位器
    saltname_locator = (By.ID, 'saltname')
    # 手机号码定位器
    mobile_locator = (By.ID, 'mobile')
    # 邮箱定位器
    email_locator = (By.ID, 'email')
    # 选择省份定位器
    state_locator = (By.NAME, "address['state']")
    # 选择城市定位器
    city_locator = (By.NAME, "address['city']")
    # 选择市区定位器
    area_locator = (By.NAME, "address['area']")
    # 选择街道定位器
    street_locator = (By.NAME, "address['street']")
    # 下次联系时间定位器
    nextstep_time_locator = (By.ID, 'nextstep_time')
    # 下次联系内容定位器
    nextstep_locator = (By.ID, 'nextstep')
    # 备注框框定位器
    beizhu_locator = (By.CSS_SELECTOR, '#form1 > table > tbody > tr:nth-child(9) > td.tdleft')
    # 备注内容定位器
    description_locator = (By.ID, 'description')
    # 保存定位器
    preserve_locator = (By.CSS_SELECTOR, '#form1 > table > tfoot > tr > td > input:nth-child(1)')

    # 获取当前页面地址
    def get_current_url(self):
        return self.driver.current_url

    # 输入负责人
    def input_person(self,person):
        self.driver.find_element(*self.person_locator).clear()
        self.driver.find_element(*self.person_locator).send_keys(person)

    # 输入公司名
    def input_company(self,company):
        self.driver.find_element(*self.company_locator).send_keys(company)

    # 点击公司名
    def click_company_name(self):
        self.driver.find_element(*self.click_company).click()
        self.driver.switch_to.alert.accept()

    # 点击公司验重
    def click_company_yanchong(self):
        self.driver.find_element(*self.company_yanchong_locator).click()

    # 选择来源
    def choose_source(self,value):
        select_source = self.driver.find_element(*self.source_locator)
        Select(select_source).select_by_value(value)

    # 输入联系人姓名
    def input_contacts_name(self,name):
        self.driver.find_element(*self.contacts_name_locator).send_keys(name)

    # 输入职位
    def input_position(self,position):
        self.driver.find_element(*self.position_locator).send_keys(position)

    # 选择尊称
    def choose_saltname(self,index):
        select_saltname = self.driver.find_element(*self.saltname_locator)
        Select(select_saltname).select_by_index(index)

    # 输入手机号码
    def input_mobile(self,mobile):
        self.driver.find_element(*self.mobile_locator).send_keys(mobile)

    # 输入邮箱
    def input_email(self,email):
        self.driver.find_element(*self.email_locator).send_keys(email)

    # 选择省份
    def choose_state(self,value):
        select_state = self.driver.find_element(*self.state_locator)
        Select(select_state).select_by_value(value)

    # 选择城市
    def choose_city(self,value):
        select_city = self.driver.find_element(*self.city_locator)
        Select(select_city).select_by_value(value)

    # 选择市区
    def choose_area(self,value):
        select_area = self.driver.find_element(*self.area_locator)
        Select(select_area).select_by_value(value)

    # 输入街道
    def input_street(self,street):
        self.driver.find_element(*self.street_locator).send_keys(street)

    # 输入下次联系时间
    def input_nextstep_time(self,time):
        self.driver.find_element(*self.nextstep_time_locator).send_keys(time)

    # 输入下次联系内容
    def input_nextstep(self,content):
        self.driver.find_element(*self.nextstep_locator).send_keys(content)

    # 点击备注框空白区域
    def click_beizhu(self):
        self.driver.find_element(*self.beizhu_locator).click()

    # 输入备注内容
    def input_description(self,content):
        self.driver.find_element(*self.description_locator).send_keys(content)

    # 点击保存
    def click_preserve(self):
        self.driver.find_element(*self.preserve_locator).click()

    # 手机弹窗
    def warning_box_mobile(self):
        self.click_preserve()
        warn = self.driver.switch_to.alert.text
        return warn

    # 联系人弹框
    def warning_box_contacts_name(self):
        self.click_preserve()
        warn = self.driver.switch_to.alert.text
        return warn